<?php
/**
 * Description
 *
 * PHP version 7
 *
 * @category Custom
 * @package  Custom
 * @author   ryu <mo5467@126.com>
 * @date     2020-04-28 23:41:01
 * @lastTime 2020-04-28 23:54:01
 * @license  https://opensource.org/licenses/MIT MIT License
 * @link     none
 */
namespace Design\Behavioral\Observer;

class User implements \SplSubject
{

    private $email;

    private $observers;


    public function __construct()
    {
        $this->observers = new \SplObjectStorage();

    }//end __construct()


    public function attach(\SplObserver $observer)
    {
        $this->observers->attach($observer);

    }//end attach()


    public function detach(\SplObserver $observer)
    {
        $this->observers->detach($observer);

    }//end detach()


    public function changeEmail(string $email)
    {
        $this->email = $email;
        $this->notify();

    }//end changeEmail()


    public function notify()
    {
        foreach ($this->observers as $observer) {
            $observer->update($this);
        }

    }//end notify()


}//end class
